﻿@inject FlagrumDbContext Context

<AutosizeModal @ref="Modal">
    <HeaderView>
        <span class="text-grey-300 flex-grow">Error</span>
    </HeaderView>
    <BodyView>
        <div class="text-center w-full">
            <h3 class="mb-4 text-grey-300">File Corruption Detected</h3>
            <span class="block mb-10">
                One or more of the game files that this mod targets has become corrupted.
                <br/><br/>
                To fix this issue, the best approach is to disable all of your mods in the Mod Manager,
                and then restore the original game files.<br/>
                <Hyperlink Text="Guide to fixing broken game state" Uri="https://github.com/Kizari/Flagrum/wiki/Using-the-Mod-Manager#fixing-a-broken-game"/>
                <br/><br/>
                It is recommended that you force disable this mod card so that it is in the disabled state for when
                you have restored your game files.<br/>
                This will <strong>not</strong> disable the mod or resolve the issue,
                it will simply tell Flagrum that the mod is no longer applied to the game.
            </span>
            <Button Text="Force Disable" OnClick="ForceDisable" CssClass="mr-1.5 mb-6"/>
            <Button Text="Cancel" OnClick="() => Modal.Close()" CssClass="ml-1.5 mb-6"/>
        </div>
    </BodyView>
</AutosizeModal>

@code
{
    // TODO: This modal needs localisation
    
    [CascadingParameter]
    public ModCard Parent { get; set; }
    
    private int ModId { get; set; }
    
    private AutosizeModal Modal { get; set; }

    public void Open(int modId)
    {
        ModId = modId;
        Modal.Open();
    }

    private void ForceDisable()
    {
        var mod = Context.EarcMods.FirstOrDefault(m => m.Id == ModId);

        if (mod != null)
        {
            mod.IsActive = false;
            Context.SaveChanges();
        }
        
        Parent.CallModListStateHasChanged();
        Modal.Close();
    }
}
